// stack w/ array
#include <stdio.h>

const int N = 5;
int stack[5];
int top = -1;

void push(int x)
{
    if (top >= N-1)
        printf("Overflow!");
    else
    {
        top++;
        stack[top] = x;
    }
}

int pop()
{
    int temp;
    if(top <= -1)
    {
        printf("Underflow ");
        return -1;
    }
    else
    {
        temp = stack[top];
        top--;
        return temp;
    }
}

void peek()
{
    if (top <= -1)
        printf("Empty");
    else
        printf("%d", stack[top]);
}

void display()
{
    for (int i = top; i>=0; i--)
    {
        printf("%d ", stack[i]);
    }
}

int main()
{
    int k;
    do
    {
        int i;
        printf("\n1:Push - 2:Pop - 3:Peek - 4:Display: ");
        scanf("%d", &k);
        switch (k)
        {
        case 1:
            printf("Enter Item to be pushed: ");
            scanf("%d", &i);
            push(i);
            break;
        case 2:
            printf("%d\n", pop());
            break;
        case 3:
            peek();
            break;
        case 4:
            display();
            break;
        default:
            printf("Invalid choice\n");
            break;
        }
    } while (k != 0);
}